package com.example.cloudstreamrabbitmqconsumer8802.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableBinding(Sink.class)
public class ReceiveMessageListenerController {
    @Value("${server.port}")
    private String serverPort;

    @StreamListener(Sink.INPUT)
    public void input(Message<String> message) {
        System.out.println("端口:" + serverPort + "\t message.Payload:" + message.getPayload());
        /**
         *message: [payload=60cefc04-2f86-440c-aee2-170194a4720b, headers={amqp_receivedDeliveryMode=PERSISTENT, amqp_receivedExchange=studyExchange, amqp_deliveryTag=2, deliveryAttempt=1, amqp_consumerQueue=studyExchange.anonymous.IWIBkuxpTSyUHso6cXhoaQ, amqp_redelivered=false, amqp_receivedRoutingKey=studyExchange, amqp_timestamp=Thu Dec 23 17:39:05 CST 2021, amqp_messageId=93fe1b21-f1a5-0f25-03de-1904b70715fd, id=9be79574-96f3-afb8-9ede-026606dc5df8, amqp_consumerTag=amq.ctag-i6AetPqCWOJ2B964ySCWHg, sourceData=(Body:'60cefc04-2f86-440c-aee2-170194a4720b' MessageProperties [headers={}, timestamp=Thu Dec 23 17:39:05 CST 2021, messageId=93fe1b21-f1a5-0f25-03de-1904b70715fd, contentType=application/json, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=studyExchange, receivedRoutingKey=studyExchange, deliveryTag=2, consumerTag=amq.ctag-i6AetPqCWOJ2B964ySCWHg, consumerQueue=studyExchange.anonymous.IWIBkuxpTSyUHso6cXhoaQ]), contentType=application/json, timestamp=1640252345418}]
         */
    }
}
